package com.bml.client.secret.demo.aqs;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;

public class CyclicBarrierTest {

    public static void main(String[] args) throws InterruptedException {
//        long time = 5;
//        System.out.println(TimeUnit.SECONDS.toSeconds(time));
//        System.out.println(TimeUnit.SECONDS.toMillis(time));
//        TimeUnit.SECONDS.sleep(3);
//        TimeUnit.MILLISECONDS.sleep(3000);
//        TimeUnit.MINUTES.sleep(1);
        System.out.println("ok");

        CyclicBarrier barrier = new CyclicBarrier(3);
        for (int i = 1; i <= 5; i++) {
            int num = i;
            new Thread(()->{
                try {
                    System.out.println( num +"号选手准备中...");
                    barrier.await();
                    System.out.println( num +"号选手准备完成");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();

        }



    }
}
